Jupyter 101

After this tutorial, you will learn how to manipulate and represent data with jupyter and python. You can clone the tutorial by the following command.

git clone  git@github.com:g0vhk-io/sitcon-hk-2017-jupyter-tutorial.git

What is jupyter

Simple Mark Down


In [4]:
from IPython.display import YouTubeVideo
YouTubeVideo('oHg5SJYRHA0')


Out[4]:

In [29]:
%%HTML
<h1>Hello World</h1>
<pre>
int main() {
    return 0;
}
</pre>


Hello World

int main() {
    return 0;
}

In [30]:
!pip freeze


appnope==0.1.0
bleach==2.0.0
certifi==2017.7.27.1
chardet==3.0.4
decorator==4.1.2
entrypoints==0.2.3
html5lib==0.999999999
idna==2.6
ipykernel==4.6.1
ipython==6.2.0
ipython-genutils==0.2.0
ipywidgets==7.0.1
jedi==0.11.0
Jinja2==2.9.6
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.1.0
jupyter-console==5.2.0
jupyter-core==4.3.0
MarkupSafe==1.0
mistune==0.7.4
nbconvert==5.3.1
nbformat==4.4.0
notebook==5.1.0
numpy==1.13.2
pandas==0.20.3
pandocfilters==1.4.2
parso==0.1.0
pexpect==4.2.1
pickleshare==0.7.4
plotly==2.0.15
prompt-toolkit==1.0.15
ptyprocess==0.5.2
Pygments==2.2.0
python-dateutil==2.6.1
pytz==2017.2
pyzmq==16.0.2
qtconsole==4.3.1
requests==2.18.4
simplegeneric==0.8.1
six==1.11.0
terminado==0.6
testpath==0.3.1
tornado==4.5.2
traitlets==4.3.2
urllib3==1.22
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.0.3

In [13]:
import plotly
import pandas as pd


df = pd.read_csv('water.csv')
del df['Remarks']
df[df['Year']>2010]


Out[13]:
Year quantity expenditure
14 2011 818 3344
15 2012 709 3539
16 2013 612 3743
17 2014 724 3959
18 2015 766 4223

Water Quantity


In [22]:
import plotly.plotly as py
import plotly.graph_objs as go

quantities = go.Scatter(
    x = df['Year'],
    y = df['quantity'],
    name = 'quantity'
)

expenditures = go.Scatter(
    x = df['Year'],
    y = df['expenditure'],
    name = 'expenditure'
)

data = [quantities, expenditures]
plotly.tools.set_credentials_file(username='g0vhkio', api_key='EExyKfq9fHDaO8Or7NXL')

py.iplot(data, filename='basic-line', title='Water')


High five! You successfully sent some data to your account on plotly. View your plot in your browser at https://plot.ly/~g0vhkio/0 or inside your plot.ly account where it is named 'basic-line'
Out[22]:

In [ ]:


In [ ]:


In [ ]: